@extends('notice.layouts.admin')

@section('title','通知列表')

@section('css')
    <link rel="stylesheet" href="{{ asset('static/admin/plugins/datatables/dataTables.bootstrap.css') }}">
@endsection

@section('js')
 <script src="{{ asset('static/admin/plugins/datatables/jquery.dataTables.min.js') }}"></script>
 <script src="{{ asset('static/admin/plugins/datatables/dataTables.bootstrap.min.js') }}"></script>
 <script>
     var dataTable=null;

     $(function(){

         //数据表格
         dataTable = $("#dataTable").DataTable({
             //配置
             "bAutoWidth": true,//自动宽度
             "bServerSide": true,//是否从服务器
             "bSort": true, //是否允许排序
             "sAjaxSource": "/noticeApi/notice",
             "iDisplayLength": 10, //默认每页显示多少条数据
             "bStateSave":true, //使用了翻页或者改变了每页显示数据数量，会保存在cookie中，下回访问时会显示上一次关闭页面时的内容。
             "oLanguage": {
                 "sProcessing": "正在加载中...",
                 "sLengthMenu": "每页显示 _MENU_ 条记录",
                 "sZeroRecords": "抱歉, 没有匹配的数据",
                 "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                 "sInfoEmpty": "没有数据",
                 "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                 "sSearch": "搜索",
                 "sLengthMenu": "_MENU_ 页/条",
                 "oPaginate": {
                     "sFirst": "首页",
                     "sPrevious": "上一页",
                     "sNext": "下一页",
                     "sLast": "尾页"
                 },
                 "sZeroRecords": "没有检索到数据"
             },
             "aaSorting": [
                 [0, 'desc'],
                 [5]
             ],
             "aoColumns": [
                 { "data": "id" },
                 { "data": "content", "bSortable": false },
                 { "data": "times", "bSortable": false },
                 { "data": "created_at", "bSortable": false },
                 { "data": "updated_at"},
                 { "data": "id", "bSortable": false },
             ],
             "columnDefs" : [
                 //操作
                 {
                     "render" : function(data, type, row) {
                         if(data > 0) {
                             var opt_html = '';
                             opt_html += "<a href='{{ url('notice/notice') }}/"+data+"' class='X-Small btn-xs text-info'><i class='fa fa-send'></i> 详情</a>";
                             opt_html += "<a href='{{ url('notice/notice') }}/"+data+"/edit' class='X-Small btn-xs text-success'><i class='fa fa-edit'></i> 编辑</a>";
                             opt_html += "<a href='javascript:;' onclick='delData("+data+")' class='X-Small btn-xs text-danger'><i class='fa fa-times-circle'></i> 删除</a>";
                             return opt_html;
                         }
                     },
                     "targets": 5
                 }
             ],
         });

         dataTable.on('preXhr.dt', function () {
             loadShow();
         });
         dataTable.on('draw.dt', function () {
             loadShow(0);
         });
     })


     /**
      * 删除数据
      * @param $id
      */
     function delData(id)
     {
         id = parseInt(id);
         fc_confirm("您要确认删除该消息么?", function(){
             fc_ajax("/noticeApi/notice/"+id, {_method:'delete'}, 'post', 'json', function(res){
                 if(res.status == 'successful'){
                     //刷新数据
                     dataTable.ajax.reload();
                     fc_msg("删除成功!", 1);
                     return;
                 }
                 fc_msg(res.errors.message, 0);
             });
         });
     }
 </script>
@endsection

@section('content')
    <div class="box">
        <div class="box-header with-border">
            <h3 class="box-title">通知列表</h3>
        </div>
        <!-- /.box-header -->
        <div class="box-body table-responsive">
            <table id="dataTable" class="table table-bordered table-striped">
                <thead>
                <tr>
                    <th colspan="6">
                        <a href="{{ url('notice/notice/create') }}" class='btn btn-success btn-sm'>添加通知</a>
                    </th>
                </tr>
                <tr>
                    <th>通知ID</th>
                    <th>通知内容</th>
                    <th>通知次数</th>
                    <th>添加时间</th>
                    <th>编辑时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
        <!-- /.box-body -->
    </div>
@endsection



